package com.legna.xyq.alert.controller;

import com.legna.xyq.alert.service.AlertService;
import com.legna.xyq.alert.service.ColorDetectionService;
import com.legna.xyq.alert.service.HeartBeatService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/xyq")
public class XyqController {

    @Resource
    private ColorDetectionService colorDetectionService;
    @Resource
    private AlertService alertService;
    @Resource
    private HeartBeatService heartBeatService;

    @GetMapping("/heartbeat")
    public String heartbeat(){
        heartBeatService.heartbeat();
        return "success";
    }

    @GetMapping("/message/switch")
    public String switchMessageFun(){
        Boolean switchStatus = colorDetectionService.switchSendFun();
        return "挂机消息提醒当前状态："+ switchStatus;
    }

    @GetMapping("/add/email")
    public String addEmail(String addEmail){
        List<String> colorReceive = colorDetectionService.addReceiver(addEmail);
        List<String> alertReceive = alertService.addReceiver(addEmail);
        return "挂机消息提醒:"+colorReceive.toString() +
                "离线监测提醒:"+alertReceive.toString();
    }

    @GetMapping("/remove/email")
    public String removeEmail(String removeEmail){
        List<String> colorReceive = colorDetectionService.removeReceiver(removeEmail);
        List<String> alertReceive = alertService.removeReceiver(removeEmail);
        return "挂机消息提醒:"+colorReceive.toString() +
                "离线监测提醒:"+alertReceive.toString();
    }

    @GetMapping("/online/switch")
    public String switchOnlineFun(){
        Boolean switchStatus = alertService.switchSendFun();
        return "离线监测当前状态："+ switchStatus;
    }
}
